package cn.cvs.controller;

import cn.cvs.pojo.Handset;
import cn.cvs.service.HandsetService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/handSet")
public class HandSetController {
    @Autowired
    private HandsetService service;
    @RequestMapping("/list")
    public String list(Model model){
        List<Handset> list = service.selectList();
        model.addAttribute("list",list);
        return "index";
    }
    @RequestMapping("/one")
    public String one(Model model,int hsId){
        Handset handsets = service.selectOne(hsId);
        model.addAttribute("handset",handsets);
        return "info";
    }
    @ResponseBody
    @RequestMapping("/del")
    public Object del(int hsId){
        int r = service.del(hsId);
        String data = JSON.toJSONString(r);
        return data;
    }
}
